﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Permissions;

namespace FileChangingScan
{
    class Scan
    {
         [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
        static void Main(string[] args)
        {
            FileSystemWatcher watchPesho = new FileSystemWatcher("C:\\pesho");
            watchPesho.Filter = "pesho.txt";
            watchPesho.Changed+=new FileSystemEventHandler(watchPesho_Changed);
            watchPesho.EnableRaisingEvents = true;
            Console.WriteLine("Press \'q\' to quit the sample.");
            while (Console.Read() != 'q') ;
        }
         private static void watchPesho_Changed(object source, FileSystemEventArgs e) 
         {
             StreamReader pesho = new StreamReader(e.FullPath);
             using (pesho) 
             {
                 string toPrint = pesho.ReadToEnd();
                 Console.WriteLine(toPrint);
             }
         }
    }
}
